<script>
//文本预览模块
import SheetLoader from '@/utils/sheet-loader';

export default {
  name: 'TextViewer',
  props: {
    //数据ID
    dataId: {
      type: String,
      default() {
        return '';
      },
    },
  },
  data() {
    return {
      //数据加载器
      sheetLoader: null,
      //数据标题
      title: '',
      //文本内容
      data: '',
    };
  },
  async mounted() {
    this.sheetLoader = new SheetLoader(this.dataId);
    const response = await this.sheetLoader.getData();
    this.title = `预览 "${this.sheetLoader.dataInfo.name}" JSON数据`;
    this.data = JSON.stringify(response, null, 2);
    this.$emit('dataLoaded', {
      title: this.title,
      data: response,
    });
  },
  methods: {
    //导出数据
    exportData() {},
  },
};
</script>

<template>
  <pre>
    {{ data }}
  </pre>
</template>

<style lang="less">
</style>
